package com.ruoyi.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.article.domain.ArticleTagReferenced;
import com.ruoyi.article.service.IArticleTagReferencedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章标签 Controller
 * 
 * @author ruoyi
 * @date 2022-02-04
 */
@RestController
@RequestMapping("/article/tag/referenced")
public class ArticleTagReferencedController extends BaseController
{
    @Autowired
    private IArticleTagReferencedService articleTagReferencedService;

    /**
     * 查询文章标签 列表
     */
    @PreAuthorize("@ss.hasPermi('article:referenced:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleTagReferenced articleTagReferenced)
    {
        startPage();
        List<ArticleTagReferenced> list = articleTagReferencedService.selectArticleTagReferencedList(articleTagReferenced);
        return getDataTable(list);
    }

    /**
     * 导出文章标签 列表
     */
    @PreAuthorize("@ss.hasPermi('article:referenced:export')")
    @Log(title = "文章标签 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleTagReferenced articleTagReferenced)
    {
        List<ArticleTagReferenced> list = articleTagReferencedService.selectArticleTagReferencedList(articleTagReferenced);
        ExcelUtil<ArticleTagReferenced> util = new ExcelUtil<ArticleTagReferenced>(ArticleTagReferenced.class);
        util.exportExcel(response, list, "文章标签 数据");
    }

    /**
     * 获取文章标签 详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:referenced:query')")
    @GetMapping(value = "/{atrId}")
    public AjaxResult getInfo(@PathVariable("atrId") Long atrId)
    {
        return AjaxResult.success(articleTagReferencedService.selectArticleTagReferencedByAtrId(atrId));
    }

    /**
     * 新增文章标签 
     */
    @PreAuthorize("@ss.hasPermi('article:referenced:add')")
    @Log(title = "文章标签 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleTagReferenced articleTagReferenced)
    {
        return toAjax(articleTagReferencedService.insertArticleTagReferenced(articleTagReferenced));
    }

    /**
     * 修改文章标签 
     */
    @PreAuthorize("@ss.hasPermi('article:referenced:edit')")
    @Log(title = "文章标签 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleTagReferenced articleTagReferenced)
    {
        return toAjax(articleTagReferencedService.updateArticleTagReferenced(articleTagReferenced));
    }

    /**
     * 删除文章标签 
     */
    @PreAuthorize("@ss.hasPermi('article:referenced:remove')")
    @Log(title = "文章标签 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{atrIds}")
    public AjaxResult remove(@PathVariable Long[] atrIds)
    {
        return toAjax(articleTagReferencedService.deleteArticleTagReferencedByAtrIds(atrIds));
    }
}
